package com.wjbgn.electronicnian.convert;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wjbgn.electronicnian.dto.NianWordsDTO;
import com.wjbgn.electronicnian.entity.NianWordsDO;
import com.wjbgn.electronicnian.util.BeanCopierUtil;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Description: 
 * Create Date: 2022-01-20T11:06:12.907434600
 * @author weirx
 * @version 1.0
 */
@Component
public class NianWordsDoConvert {

    /**
     * DtoToDo
     *
     * @param nianWordsDTO
     * @return
     */
    public static NianWordsDO dtoToDo(NianWordsDTO nianWordsDTO) {
            NianWordsDO nianWordsDO = new NianWordsDO();
        BeanCopierUtil.copy(nianWordsDTO, nianWordsDO);
        return nianWordsDO;
    }

    /**
     * DoToDto
     *
     * @param nianWordsDO
     * @return
     */
    public static NianWordsDTO doToDto(NianWordsDO nianWordsDO) {
            NianWordsDTO nianWordsDTO = new NianWordsDTO();
        BeanCopierUtil.copy(nianWordsDO, nianWordsDTO);
        return nianWordsDTO;
    }

    /**
     * Page<DO> to Page<DTO>
     *
     * @param pageDO
     * @return
     */
    public static Page<NianWordsDTO> pageConvert(Page<NianWordsDO> pageDO) {
        List<NianWordsDTO> list = listConvert(pageDO.getRecords());
        Page<NianWordsDTO> page = new Page<>(pageDO.getCurrent(), pageDO.getSize(), pageDO.getTotal());
        page.setRecords(list);
        return page;
    }

    /**
     * list<DO> to list<DTO>
     *
     * @param listDO
     * @return
     */
    public static List<NianWordsDTO> listConvert(List<NianWordsDO> listDO) {
        List<NianWordsDTO> list = new ArrayList<>();
            NianWordsDTO nianWordsDTO;
        for (NianWordsDO nianWordsDO : listDO) {
                nianWordsDTO = new NianWordsDTO();
            BeanCopierUtil.copy(nianWordsDO, nianWordsDTO);
            list.add(nianWordsDTO);
        }
        return list;
    }
}